package com.woniu.controller;

import com.woniu.constant.Constant;
import com.woniu.entity.Result;
import com.woniu.pojo.PlatformInformation;
import com.woniu.service.PlatformInformationService;
import com.woniu.utils.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/platformInformation")
public class PlatformInformationController extends BaseController {
    @Autowired
    private PlatformInformationService platformInformationService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @PostMapping("/save")
    @ApiOperation("保存平台消息")
    public Result save(@RequestBody PlatformInformation platformInformation){
        boolean flag = platformInformationService.save(platformInformation);
        // 将图片的名称存储到Redis中
        if (flag){
            stringRedisTemplate.opsForSet().add(Constant.REDIS_DB_UPLOAD_IMAGE,platformInformation.getPlatformLogo());
        }
        return new Result(200,"保存平台消息成功",flag);
    }
}
